// 图片状态过滤器
let is_enableFilter = (val) => {
    if (val === 0) {
        return "已经上架"
    } else {
        return "已经下架"
    }
}
let is_enableBanner = (val) => {
    if (val === 0) {
        return "开启状态"
    } else {
        return "关闭状态"
    }
}

let topicStatusFilter = (val) => {
    if (val === 0) {
        return "开启"
    } else {
        return "关闭"
    }
}

let timestampToDate=(val)=>{
    if(val){
        return new Date(parseInt(val) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
    }
}


let fomatFloat = (num, n) => {
    // num为传入的值，n为保留的小数位
    var f = parseFloat(num);
    if (isNaN(f)) {
        return false;
    }
    f = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); // n 幂   
    var s = f.toString();
    var rs = s.indexOf('.');
    //判定如果是整数，增加小数点再补0
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + n) {
        s += '0';
    }
    return s;
}

let fillImgShot = (v) => {
    return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/api/base/get-shot?img=${v}`
}

let linkTypeFilter = (v) => {
    if (v === 1) {
        return "分类"
    } else if (v === 2) {
        return "标签"
    } else if (v === 3) {
        return "专题"
    } else if (v === 4) {
        return "链接"
    }
}
let recommendTypeFilter = (v)=>{
    if (v === 1) {
        return "热门用途"
    } else if (v === 2) {
        return "热门风格"
    } else if (v === 3) {
        return "精选素材"
    }
}

let nameByIdFilter = (tag_id, arr) => {
    for (var i of arr) {
        if (i.id == tag_id) {
            return i.name
        }
    }
}

let typesOfFilter=(v)=>{
    if (v===1) {
        return '按分类/标签/图片跳转'
    }else{
        return '按链接跳转'
    }
}
let createTimeFilter=(v)=>{
    var date=new Date(v*1000)
    return date.toLocaleDateString()
}

let homePositionFilter=(v,op)=>{
    for(var o of op){
        if(v==o.value){
            return o.label;
        }
    }
}

// 填充上传的图片
let fillUpImgShot = (v) => {
    // return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/get-image?img=${v}`
    return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/api/base/get_image?img=${v}`
}


let getStaticImg = (v) => {
    if(!v) return false
    if( v.startsWith('temp_files/') ){
        return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/${v}`
    }else {
        return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/images/${v}`
    }
    
}
let getStaticIcon = (v) => {
    if(!v) return false
    if( v.startsWith('temp_files/') ){
        return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/${v}`
    }else {
        return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/icons/${v}`
    }
    
}
let getTempFile = (v) => {
    // return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/images/${v}`
    return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/temp_files/${v}`
}

// 根据分类id获取分类名称
let roleFilter=(v,list)=>{
    for(var o of list){
        if(o.value===v){
            return o.label
        }
    }
}
export {
    is_enableFilter,
    is_enableBanner,
    topicStatusFilter,
    fomatFloat,
    fillImgShot,
    linkTypeFilter,
    getStaticImg,
    getTempFile,
    nameByIdFilter,
    typesOfFilter,
    createTimeFilter,
    homePositionFilter,
    fillUpImgShot,
    timestampToDate,
    recommendTypeFilter,
    roleFilter,
    getStaticIcon
}


